﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using OpenQuant;
using QuantBox;
using Skyline;
using SmartQuant;

namespace CtpseDemo
{
    public class DataManageScenario : Scenario
    {
        public DataManageScenario(Framework framework) : base(framework)
        {
        }
        
        private void UpdateInstrument()
        {
            InstrumentManager.Instruments.Clear();
            //    Console.WriteLine(framework.InstrumentManager.Instruments.Count);
            var list = InstrumentManager.GetLiveFutures();
            foreach (var item in list)
            {
                if (item.Symbol.EndsWith("99"))
                {
                    Console.WriteLine(item.Symbol);
                    InstrumentManager.Add(item);
                }
            }
            //framework.InstrumentManager
        }

        private void UpdateData()
        {
            var begin = new DateTime(2020, 5, 8);
            var end = new DateTime(2022, 1, 1);
            for (var date = begin; date < end; date = date.AddDays(1))
            {
                if (!TradingCalendar.Instance.IsTradingDay(date))
                {
                    continue;
                }
                //    for
                foreach (var instrument in framework.InstrumentManager.Instruments)
                {
                    var (asks, bids, trades) = framework.DataManager.DownloadTicks(instrument, date, date);
                    framework.DataManager.Save(asks);
                    framework.DataManager.Save(bids);
                    framework.DataManager.Save(trades);
                }
            }
        }

        public override void Run()
        {
            XProvider.BacktestInit();
            //UpdateInstrument();
            UpdateData();
        }
    }
}